package com.huqiwen.table;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TabelOrder extends HttpServlet {

	public TabelOrder() {
		super();
	}

	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String strc = request.getParameter("str");
		String temp[]=strc.split("&");
		String result[] = new String[temp.length];
		try {
			Statement stmt = DataSource.getConnection().createStatement();
			for (int i = 0; i < result.length; i++) {
				result[i]=temp[i].substring(8);
				System.out.println(result[i]);
				String sql = "update tabletest set orders="+i+" where id ="+result[i];
				System.out.println(sql);
				stmt.executeUpdate(sql);
				
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		PrintWriter out = response.getWriter();
		out.println("ok");
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

	public void init() throws ServletException {
		// Put your code here
	}

}
